﻿using System.Data;
using ContractManagementSystem.DataAccessLayer;
using ContractManagementSystem.EntityObjects;

namespace ContractManagementSystem.BusinessLogicLayer
{
    public static class ConsultantProfileLogic
    {
        #region"Get consultant"
        //Get all consultant
        public static DataTable SelectData()
        {
            return ConsultantDao.SelectAllData();
        }
        //Get consultant by id
        public static DataTable SelectConsultantByConsultantId(string consultantId)
        {
            return ConsultantDao.SelectConsultantById(consultantId);
        }
        //Get consultant by user name
        public static DataTable SelectConsultantByUserName(string user)
        {
            return ConsultantDao.SelectConsultantByUserName(user);
        }
        #endregion

        #region"insert/delete/update"

        public static string InsertConsultants(ConsultantEntity consultant)
        {
            if(!CheckBeforeSave(consultant))
            {
                return null;
            }
            if(CheckExistEmailValue(consultant.Email))
            {
                return "Existing email!";
            }
            string insert = ConsultantDao.InsertConsultant(consultant);
            return insert;
        }

        public static string UpdateConsultants(ConsultantEntity consultant)
        {
            if (!CheckBeforeSave(consultant))
            {
                return null;
            }
            string update = ConsultantDao.UpdateConsultant(consultant);
            return update;

        }

        public static string DeleteConsultant(ConsultantEntity consultant)
        {
            string delete = ConsultantDao.DeleteConsultant(consultant);
            return delete;
        }

        #endregion

        #region"Search"
        //search
        public static DataTable SearchConsultant(string fullName, string companyName)
        {
            var dataTable = ConsultantDao.SearchConsultant(fullName, companyName);
            return dataTable;
        }
        #endregion

        //Check exist emails
        public static bool CheckExistEmailValue(string value)
        {
            bool result = ConsultantDao.CheckExistEmailValue(value);
            return result;
        }
        //check before saving
        public static bool CheckBeforeSave(ConsultantEntity consultant)
        {
            if(string.IsNullOrEmpty(consultant.FullName))
            {
                return false;
            }
            if(string.IsNullOrEmpty(consultant.Email))
            {
                return false;
            }
            if(string.IsNullOrEmpty(consultant.CompanyName))
            {
                return false;
            }
            if(string.IsNullOrEmpty(consultant.PhoneNumber))
            {
                return false;
            }
            if(string.IsNullOrEmpty(consultant.Address))
            {
                return false;
            }
            return true;
        }
    }
}
